package com.aos.erp.schools.rest.branchschool;


import com.aos.erp.common.bean.IPageBean;
import com.aos.erp.common.bean.ResultEntity;
import com.aos.erp.common.exception.BizException;
import com.aos.erp.schools.model.branchschool.entity.BranchSchool;
import com.aos.erp.schools.model.branchschool.ro.BranchSchoolRo;
import com.aos.erp.schools.model.branchschool.ro.UpdateBranchSchoolRo;
import com.aos.erp.schools.model.branchschool.vo.ListBranchSchoolVo;
import com.aos.erp.schools.model.registerschool.ro.RegisterSchoolRo;
import com.aos.erp.schools.model.registerschool.ro.UpdateRegisterSchoolRo;
import com.aos.erp.schools.model.registerschool.vo.ListRegisterSchoolVo;
import com.aos.erp.schools.service.branchschool.BranchSchoolService;
import com.aos.erp.schools.service.registerschool.RegisterSchoolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 分校 前端控制器
 * </p>
 *
 * @author 杨文博
 * @since 2018-12-02
 */
@Slf4j
@RestController
@RequestMapping("/api/branch")
@Api(value="分校接口rest",tags={"分校接口rest"})
public class BranchSchoolController {

	@Autowired
	private BranchSchoolService branchSchoolService;



	@GetMapping("/list")
	@ApiOperation(value = "分页查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageIndex",value = "分页",dataType ="int",paramType ="query" ),
			@ApiImplicitParam(name = "pageSize",value = "分页",dataType ="int",paramType ="query" ),
			@ApiImplicitParam(name = "name",value = "报名点名称",dataType ="String",paramType ="query" )}
	)
	public ResultEntity<IPageBean<ListBranchSchoolVo>> queryPageBean(@RequestParam(name = "pageIndex", defaultValue = "1") Integer pageIndex, @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize, @RequestParam(name = "name",required=false) String name,String currentUserId) throws Exception {
		return ResultEntity.success(branchSchoolService.queryByPage(pageIndex, pageSize,name,currentUserId));
	}






	@ApiOperation(value = "新增分校", notes = "新增分校")
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	public ResultEntity addBranch(@Validated BranchSchoolRo branchSchoolRo) {
		try {
			int count=branchSchoolService.addBranch(branchSchoolRo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResultEntity.success();
	}

	@ApiOperation(value = "删除分校", notes = "删除分校")
	@RequestMapping(value = "/delete",method = RequestMethod.POST)
	@ApiImplicitParam(name = "id",value = "分校id",required = true,dataType ="long",paramType ="query" )
	public  ResultEntity deleteBranch(Long id) throws BizException {
		//System.out.println(ids.toString());
		branchSchoolService.deleteBranch(id);
		return ResultEntity.success();
	}


/**
	 * 获取报名点信息
	 * @[param id  报名点id
	 * @return
	 */

	@ApiOperation(value = "获取分校信息", notes = "获取分校信息")
	@RequestMapping(value = "/info", method = RequestMethod.POST)
	@ApiImplicitParam(name = "id",value = "分校id",required = true,dataType ="long",paramType ="query" )
	public ResultEntity branchInfo(Long id){
		if(id==null){
			return ResultEntity.failed("参数不能为空");
		}
		return ResultEntity.success(branchSchoolService.branchInfo(id));
	}


/**
	 * 修改报名点
	 * @[param UpdateDivisionRos  报名点实体
	 * @return
	 */

	@ApiOperation(value = "修改分校", notes = "修改分校")
	@RequestMapping(value = "/update",method = RequestMethod.POST)
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id",required = true, value = "主键", dataType = "long",paramType ="query"),
		@ApiImplicitParam(name = "parentId",required = true, value = "父级驾校ID", dataType = "long",paramType ="query"),
		@ApiImplicitParam(name = "name",required = true, value = "分校名称", dataType = "String",paramType ="query"),
		@ApiImplicitParam(name = "address",required = true, value = "详细地址", dataType = "String",paramType ="query"),
		@ApiImplicitParam(name = "contacts",required = true, value = "联系人", dataType = "String",paramType ="query"),
		@ApiImplicitParam(name = "mobile",required = true, value = "手机号", dataType = "String",paramType ="query"),
		@ApiImplicitParam(name = "latitude",required = true, value = "纬度", dataType = "String",paramType ="query"),
		@ApiImplicitParam(name = "longitude",required = true, value = "经度", dataType = "String",paramType ="query")
	})
	public ResultEntity updateBranch( @Validated UpdateBranchSchoolRo updateBranchSchoolRo){
		return branchSchoolService.updateBranch(updateBranchSchoolRo);
	}


	/**
	 * 根据总校ID获取分校
	 * @[param id  总校ID
	 * @return
	 */

	@ApiOperation(value = "根据总校ID获取分校", notes = "根据总校ID获取分校")
	@RequestMapping(value = "/getInfoByGather", method = RequestMethod.POST)
	@ApiImplicitParam(name = "id",value = "总校ID",required = true,dataType ="long",paramType ="query" )
	public ResultEntity getInfoByGather(Long id){
		if(id==null){
			return ResultEntity.failed("参数不能为空");
		}
		List<ListBranchSchoolVo> list=branchSchoolService.getInfoByGather(id);
		return ResultEntity.success(list);
	}

}

